package oj;

import java.util.ArrayList;
import java.util.List;

public class LC114 {
    public void flatten(TreeNode root) {
        List<TreeNode> list=new ArrayList<>();
        preOrder(root,list);
        for(int i=1;i<list.size();i++){
            TreeNode prev=list.get(i-1);
            TreeNode cur=list.get(i);
            prev.left=null;
            prev.right=cur;
        }
    }
    private void preOrder(TreeNode root,List<TreeNode> list){
        if(root!=null){
            list.add(root);
            preOrder(root.left,list);
            preOrder(root.right,list);
        }
    }
}
